import { createRouter, createWebHistory } from 'vue-router';
import Login from '../views/Login/index.vue';
import Home from '../views/Home/index.vue';
import DepartmentManagement from '../views/UserManagement/DepartmentManagement.vue';
import UserManagementPage from '../views/UserManagement/UserManagementPage.vue';
import RoleManagement from '../views/UserManagement/RoleManagement.vue';
import DataStatistics from '../views/DataStatistics/index.vue';
import Settings from '../views/Settings/index.vue';
import FileManagement from '../views/FileManagement/index.vue';
import HomeDefaultContent from '../views/Home/HomeDefaultContent.vue';
import MenuManagement from '../views/MenuManagement/index.vue';
import Register from '../views/register/index.vue'
const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        { path: '/login', component: Login },
        { path: '/register', component: Register },
        {
            path: '/',
            component: Home,
            meta: { requiresAuth: true },
            children: [
                { path: '', component: HomeDefaultContent },
                {
                    path: 'user-management',
                    children: [
                        { path: '', redirect: 'department' },
                        { path: 'department', component: DepartmentManagement },
                        { path: 'user', component: UserManagementPage },
                        { path: 'role', component: RoleManagement },
                    ],
                },
                { path: 'menu-management', component: MenuManagement },
                { path: 'data-statistics', component: DataStatistics },
                { path: 'file-management', component: FileManagement },
                { path: 'settings', component: Settings },
            ],
        },
    ],
});

// 路由守卫
router.beforeEach((to, from) => {
    if (to.meta.requiresAuth && !localStorage.getItem('isLogin')) {
        return '/login';
    }
});

export default router;